package com.itheima.mall.service.pms;


import cn.hutool.core.convert.Convert;
import com.itheima.mall.api.pms.ProductCategoryServiceApi;
import com.itheima.mall.dto.ProductCategoryDto;
import com.itheima.mall.pojo.pms.ProductCategory;
import com.itheima.mall.vo.pms.ProductCategoryChildrenVo;
import com.itheima.mall.vo.pms.ProductCategoryVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductCategoryService {
    @DubboReference
    private ProductCategoryServiceApi productCategoryServiceApi;

    //查询所有一级分类及子分类
    public List<ProductCategoryChildrenVo> withChildren() {
        List<ProductCategoryChildrenVo> productCategoryChildrenVo = productCategoryServiceApi.withChildren();
        return productCategoryChildrenVo;
    }


    //根据id获取商品分类
    public ProductCategory getProduct(Integer id) {
        ProductCategory productCategory = productCategoryServiceApi.getProduct(id);
        return productCategory;

    }

    //修改商品分类
    public void updateProduct(ProductCategory productCategory, Integer id) {
        productCategoryServiceApi.updateProduct(productCategory, id);
    }

    //分页查询商品分类
    public ProductCategoryVo selectPaging(Integer parentId, Integer pageNum, Integer pageSize) {
        ProductCategoryVo productCategoryVo = productCategoryServiceApi.selectPaging(parentId, pageNum, pageSize);
        return productCategoryVo;
    }

    //修改导航栏显示状态
    public void updateNavStatus(Integer navStatus, Long[] ids) {
        productCategoryServiceApi.updateNavStatus(navStatus, ids);
    }

    //修改显示状态
    public void updateshowStatus(Integer showStatus, Long[] ids) {
        productCategoryServiceApi.updateshowStatus(showStatus, ids);
    }

    /**
     * 添加商品分类
     *
     * @param productCategoryDto
     */
    public void create(ProductCategoryDto productCategoryDto) {
        productCategoryServiceApi.create(productCategoryDto);
    }

    /**
     * 删除商品分类
     *
     * @param id
     */
    public Boolean deleteById(Integer id) {
        Long productCategoryId = Convert.toLong(id);
        return productCategoryServiceApi.deleteById(productCategoryId);
    }
}






